import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
mpl.rcParams['font.sans-serif']=['SimHei']#让中文可以正常显示
plt.rcParams['axes.unicode_minus']=False #让负号能够正常显示

x=np.linspace(-5,5,50)
y=3*x+1
y2=x**2
plt.figure()
plt.title("图表标题",fontsize="small",color="red")
plt.plot(x,y,"r--",label="3*x+1")
plt.plot(x,y2,"c-.",label="x**2")
# legend显示图例，loc可以指定图例的位置
# 0: ‘best‘ 1: ‘upper right‘ 2: ‘upper left‘ 3: ‘lower left‘ 4: ‘lower right‘ 5: ‘right‘ 6: ‘center left‘
# 7: ‘center right‘ 8: ‘lower center‘ 9: ‘upper center‘ 10: ‘center
plt.legend(loc='upper right')
plt.xlim(-2,4)  #指定横坐标的刻度
plt.ylim(-5,15) #指定纵坐标的刻度
plt.xlabel("I'm x")  #指定x轴的标题
plt.ylabel("I'm y") #指定y轴的标题
plt.show()